package DBIx::Class::Component::DataValidator::DBMS::SQLite;

use strict;
use Class::C3;

use base qw/
    DBIx::Class::Component::DataValidator::DBMS
/;

our $VERSION = '0.05';

=head1 NAME

DBIx::Class::Component::DataValidator::DBMS::SQLite - validation for SQLite specific datatypes

=head1 DESCRIPTION

SQLite has only two validatables types: character (length), integer and real. These are already validated by the core Class (L<DBIx::Class::Component::DataValidator::DBMS>). Though, this is just an example class to show how additional DBMS could be registered. It simple re-registers all types from the core..

=cut


=head1 DATATYPE VALIDATORS

=head2 integer | int

for all integer values. Checks wheter only numbers are given

=head2 decimal | float | double | real

for all decimal values. Checks wheter only decimal or interger numbers are given

=head2 varchar | char | character

if a maximum size for the column is given -> checks wheter the given string isnt to long


=cut

__PACKAGE__->add_datatype_validators( {
    
    # integer, numeric types
    int     => sub {
        my ( $dv, $col_ref, $col ) = @_;
        return 0 if ! defined $col && ! $col_ref->{ is_nullable };
        return $col =~ /^\d+$/;
    },
    integer => 'map:int',
    decimal => sub {
        my ( $dv, $col_ref, $col ) = @_;
        return 0 if ! defined $col && ! $col_ref->{ is_nullable };
        return $col =~ /^\d+(?:\.\d+)?$/;
    },
    float   => 'map:decimal',
    double  => 'map:decimal',
    real    => 'map:decimal',
    
    # charcacter types
    varchar => sub {
        my ( $dv, $col_ref, $col ) = @_;
        return 0 if ! defined $col && ! $col_ref->{ is_nullable };
        if ( ( my $size = $col_ref->{ size } ) > 0 ) {
            return length( $col ) <= $col_ref->{ size };
        }
        return 1;
    },
    char      => 'map:varchar',
    character => 'map:varchar',
} );



1;
